<template>
	<el-container>
		<el-aside width="200px" v-loading="showGrouploading">
			<el-container>
				<el-header>
					<el-input placeholder="输入关键字进行过滤" v-model="groupFilterText" clearable></el-input>
				</el-header>
				<el-main class="nopadding">
					<el-tree ref="group" class="menu" node-key="deptId" :data="group" :props="groupsProps" :current-node-key="''" :highlight-current="true" :expand-on-click-node="false"
							 :filter-node-method="groupFilterNode" @node-click="groupClick"></el-tree>
				</el-main>
			</el-container>
		</el-aside>
		<el-container>
			<el-header style="height: auto;">
				<sc-select-filter :data="filterData" :label-width="80" @on-change="filterChange"></sc-select-filter>
			</el-header>
			<el-header>
				<div class="left-panel">
					<el-button type="primary" icon="el-icon-download" @click="doExpAttend">导出</el-button>
				</div>
				<div class="right-panel">
					<div class="right-panel-search">
						<el-form-item label="统计时间" style="margin-left: 20px;margin-bottom: 0px;">
							<el-date-picker
								v-model="search.date"
								type="daterange"
								value-format="YYYY-MM-DD"
								range-separator="至"
								start-placeholder="开始日期"
								end-placeholder="结束日期">
							</el-date-picker>
						</el-form-item>
						<el-form-item label="人员姓名" style="margin-left: 20px;margin-bottom: 0px;">
							<select-user-dialog v-model:accountId="search.createUser" :mode="false"/>
						</el-form-item>
						<el-button type="primary" icon="el-icon-search" @click="upsearch"></el-button>
					</div>
				</div>
			</el-header>
			<el-main class="nopadding">
				<scTable ref="table" :apiObj="apiObj" :params="{date:['','']}" stripe remoteSort remoteFilter>
					<el-table-column label="#" type="index" width="50"></el-table-column>
					<el-table-column label="人员姓名" prop="createUserName" width="150"></el-table-column>
					<el-table-column label="年" prop="year" width="120"></el-table-column>
					<el-table-column label="月" prop="month" width="100"></el-table-column>
					<el-table-column label="日" prop="day" width="100"></el-table-column>
					<el-table-column label="打卡时间" prop="time" width="100"></el-table-column>
					<el-table-column label="考勤状态" prop="type" width="150">
						<template #default="scope">
							<el-tag type="success" v-if="scope.row.type==='0'">正常</el-tag>
							<el-tag type="warning" v-else-if="scope.row.type==='1'">补打卡</el-tag>
							<el-tag type="danger" v-else-if="scope.row.type==='2'">迟到</el-tag>
							<el-tag type="danger" v-else-if="scope.row.type==='3'">由事早退</el-tag>
							<el-tag type="danger" v-else-if="scope.row.type==='4'">早退</el-tag>
							<el-tag  v-else-if="scope.row.type==='5'">旷工</el-tag>
							<el-tag type="danger" v-else >未知</el-tag>
						</template>
					</el-table-column>
					<el-table-column label="考勤类型" prop="stauts" width="150">
						<template #default="scope">
							<el-button type="primary" size="small" v-if="scope.row.stauts==='1'">上班打卡</el-button>
							<el-button type="danger" size="small" v-else-if="scope.row.stauts==='2'">下班打卡</el-button>
							<el-button type="info" size="small" v-else>未知</el-button>
						</template>
					</el-table-column>
					<el-table-column label="备注" prop="remark" width="300" :show-overflow-tooltip="true"></el-table-column>
				</scTable>
			</el-main>
		</el-container>
	</el-container>
	<expDialog v-if="dialog.expSave" ref="expSaveDialog" @closed="dialog.expSave=false"></expDialog>
</template>

<script>
import selectUserDialog from "@/views/module/selectUserDialog";
import scSelectFilter from '@/components/scSelectFilter'
import expDialog from './expdialog'
export default {
	name: 'Attend Total',
	components: {
		scSelectFilter,
		selectUserDialog,
		expDialog
	},
	data() {
		return {
			dialog: {
				save: false,
				expSave:false
			},
			filterData: [
				{
					title: "状态类型",
					key: "type",
					multiple: false,
					options: [{
						value: '',
						label: '全部'
					}, {
						value: '0',
						label: '正常'
					}, {
						value: '1',
						label: '迟到'
					}, {
						value: '2',
						label: '早退'
					}],
				}
			],
			showGrouploading: false,
			groupFilterText: '',
			group: [],
			groupsProps: {
				label: "deptName",
				value: "deptId"
			},
			apiObj: this.$API.office.attend.getTotalAttendList,
			search: {
				deptId: '',
				date: ['', ''],
				type: '',
				createUser: ''
			}
		}
	},
	watch: {
		groupFilterText(val) {
			this.$refs.group.filter(val);
		}
	},
	mounted() {
		this.getDeptGroup()
	},
	methods: {
		doExpAttend() {
			this.dialog.expSave = true
			this.$nextTick(() => {
				this.$refs.expSaveDialog.open()
			})
		},
		filterChange(data) {
			this.search.type = data.type;
			this.$refs.table.upData(this.search)
		},
		//加载树数据
		async getDeptGroup() {
			this.showGrouploading = true;
			var res = await this.$API.system.unitDept.list.get();
			this.showGrouploading = false;
			var allNode = {deptId: '', deptName: '所有'}
			res.data.unshift(allNode);
			this.group = res.data;
		},
		//树过滤
		groupFilterNode(value, data) {
			if (!value) return true;
			return data.deptName.indexOf(value) !== -1;
		},
		//树点击事件
		groupClick(data) {
			this.search.deptId = data.deptId;
			this.$refs.table.upData(this.search)
		},
		//搜索
		upsearch() {

			this.$refs.table.upData(this.search)
		},
		//本地更新数据
		handleSuccess(data, mode) {
			this.$refs.table.refresh()
		}
	}
}
</script>

<style>
</style>
